{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "     Site  Age\n",
      "0  Google   10\n",
      "1  Runoob   12\n",
      "2    Wiki   13\n",
      "     Site  Age\n",
      "0  Google   10\n",
      "1  Runoob   12\n",
      "2    Wiki   13\n",
      "     Site  Age\n",
      "0  Google   10\n",
      "1  Runoob   12\n",
      "      calories  duration\n",
      "day1       420        50\n",
      "day2       380        40\n",
      "day3       390        45\n",
      "calories    420\n",
      "duration     50\n",
      "Name: day1, dtype: int64\n",
      "      calories  duration\n",
      "day1       420        50\n"
     ]
    }
   ],
   "source": [
    "# Pandas 数据结构 - DataFrame\n",
    "#\n",
    "'''\n",
    "DataFrame 是一个表格型的数据结构, \n",
    "它含有一组有序的列，每列可以是不同的值类型（数值、字符串、布尔型值）。\n",
    "DataFrame 既有行索引也有列索引，它可以被看做由 Series 组成的字典（共同用一个索引）。\n",
    "\n",
    "pandas.DataFrame( data, index, columns, dtype, copy)\n",
    "\n",
    "参数说明：\n",
    "data    - 一组数据(ndarray、series, map, lists, dict 等类型)。\n",
    "index   - 索引值，或者可以称为行标签。\n",
    "columns - 列标签，默认为 RangeIndex (0, 1, 2, …, n) 。\n",
    "dtype   - 数据类型。\n",
    "copy    - 拷贝数据，默认为 False。\n",
    "'''\n",
    "import pandas as pd\n",
    "\n",
    "data = [['Google', 10], ['Runoob', 12], ['Wiki', 13]]\n",
    "df = pd.DataFrame(data, columns=['Site', 'Age'])\n",
    "print(df)\n",
    "\n",
    "data = {'Site': ['Google', 'Runoob', 'Wiki'], 'Age': [10, 12, 13]}\n",
    "df = pd.DataFrame(data)\n",
    "print(df)\n",
    "# 返回第一行和第二行\n",
    "print(df.loc[[0, 1]])\n",
    "\n",
    "data = {\n",
    "    \"calories\": [420, 380, 390],\n",
    "    \"duration\": [50, 40, 45]\n",
    "}\n",
    "df = pd.DataFrame(data, index=[\"day1\", \"day2\", \"day3\"])\n",
    "print(df)\n",
    "# 指定索引\n",
    "print(df.loc[\"day1\"])\n",
    "print(df.loc[[\"day1\"]])\n",
    "\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.9.9 64-bit",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.9"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "cf18841ace8313d0bc088ca146c17a6c0040e82121d5cb75c0ea07172309253d"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
